/** 发布npm包 */
import { spawnSync } from "child_process";
import { cpSync } from 'fs'

const root = process.cwd();

export default async (path?: string) => {
  if (path) {
    cpSync('package.json', `${root}${path}/package.json`, { recursive: true, force: true })
    cpSync('README.md', `${root}${path}/README.md`, { recursive: true, force: true })

    spawnSync(`cd ${root}${path} && npm publish`, { shell: true, stdio: 'inherit' })
  } else spawnSync(`npm publish`, { shell: true, stdio: 'inherit' });

  console.log('发布成功!')
}